Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

263
Vistas
How to remove the "selected" Attribute and move it to another option using Cypress?

I have tried:

cy.get(`div[class="input-group input-group-sm"] select[name="activeStatus"]`).find(":selected").invoke("removeAttr", "selected")

which doesn't work as I have hoped, but it's been the closest to it I think. Anyone have any tips? I want to move the "Selected" attribute from Active, to Cancelled.

enter image description here

about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

You're halfway there, the removal part works. To add selected to Cancelled, invoke attr

// remove
cy.get('select')
  .find(':selected')
  .should('contain', 'Active')
  .invoke('removeAttr', 'selected')

// add
cy.get('select')
  .find('option')
  .contains('Cancelled')
  .invoke('attr', 'selected', true)

//confirm
cy.get('select')
  .find(':selected')
  .should('contain', 'Cancelled')

This gives you

<option selected="selected">Cancelled</option>

If you prefer

<option selected>Cancelled</option>

use this instead

// add
cy.get('select')
  .find('option')
  .contains('Cancelled')
  .then($el => $el[0].setAttribute('selected', ''))
about 4 years ago · Juan Pablo Isaza Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda